package com.fast.develop.integration.xml.generator;

import com.fast.develop.meta.dm.MetaDomainModel;
import com.fast.develop.meta.dm.MetaField;
import com.fast.develop.meta.dm.field.FieldType;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
 * @author 莫寅
 * @createTime 2022-06-05 01:25
 * @desc：
 */
public class IdGenerator {

    private String name;
    private String column;
    private String length;
    private FieldType type;

    Document document;

    public IdGenerator(Document document, MetaDomainModel metaDomainModel) {
        MetaField metaField = metaDomainModel.getIdentifierProperty();
        this.name = metaField.getName();
        this.column = metaField.getColumnName();
        this.length = metaField.getLength() + "";
        this.type = metaField.getType().type();
        this.document = document;

    }


    /**
     *
     * <id name="id" column="id" length="32" type="string"/>
     * @return
     */
    public void generate(Node node){
        Element element = document.createElement("id");
        element.setAttribute("name", name);
        element.setAttribute("column", column);
        element.setAttribute("length", length);
        element.setAttribute("type", type.getValue());

        node.appendChild(element);
    }
}
